import advView from '$v/adv'
import {
  isLoginRequest,
  logoutRequest,
} from '../api/admin'
export default async (req, res, next) => {

  //路由切换的时候验证登录
  try {
    await isLoginRequest();
  } catch (e) {
    //请求异常后提示用户
    alert("有异常" + e.message)

    //判断是否是权限异常
    if (!e.isLogin) {
      return router.go("/login");
    }
  }

  next(advView({
    url: req.url,
    subRoute: res.subRoute()
  }));

const ologout=document.getElementById("logout")
ologout.onclick=async function(){
  try {
    await logoutRequest()
    // 退出成功清掉token
    localStorage.removeItem("user_token")
    // 跳转到登录页面
    router.go("/login")
  } catch (e) {
    alert("退出异常"+e.massage)
  }
}



}